package jsyf.oa.web.wechat.service_company;

import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wechat.service_company.EnterpriseMenuFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/enterpriseMenu")
public class EnterpriseMenuController {
    @Resource
    private EnterpriseMenuFacade enterpriseMenuFacade;

    //  创建菜单
    @RequestMapping(value = "/createMenu.json", method = RequestMethod.POST)
    public void createMenu(HttpServletResponse response, @RequestBody String jsonData) {

        // 调用接口查询
        JSONObject jsonObject = enterpriseMenuFacade.createMenu(jsonData);
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    //  获取菜单
    @RequestMapping(value = "/getMenu.json", method = RequestMethod.POST)
    public void getMenu(HttpServletResponse response) {
        // 调用接口查询
        JSONObject jsonObject = enterpriseMenuFacade.getMenu();
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    //  删除菜单
    @RequestMapping(value = "/deleteMenu.json", method = RequestMethod.POST)
    public void deleteMenu(HttpServletResponse response) {
        // 调用接口查询
        JSONObject jsonObject = enterpriseMenuFacade.deleteMenu();
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}